package api

import (
	"github.com/gin-gonic/gin"
	"lib/middleware"
)

func RegisterRouter(r *gin.RouterGroup) {
	clusterRouter(r) // 集群路由
	sessionRouter(r) // 会话路由
	wsRouter(r)
	settingsRouter(r)
	remoteApi(r)
	shHostRouter(r)
}

func clusterRouter(r *gin.RouterGroup) {
	sub := r.Group("cluster")
	sub.Use(middleware.GinAuthorizationMiddleAware())

	sub.POST("add/cluster", ClusterApi.AddCluster)
	sub.GET("list/cluster", ClusterApi.ClusterList)
	sub.DELETE("/:id", ClusterApi.DeleteCluster)
	sub.GET("hosts/:id", ClusterApi.GetClusterHost)
	sub.POST("bind/host", ClusterApi.BindHost)
	sub.POST("host/apps", ClusterApi.UpdateHostAppList)

	sub.GET("list/host", ClusterApi.HostList) // 获取主机列表
	sub.DELETE("host/:id", ClusterApi.DeleteHost)
	sub.POST("host/trim", ClusterApi.TrimHostArgus) // 微调主机参数

	sub.GET("install/app/:id", ClusterApi.GetInstallAppList)
	sub.POST("issue/app", ClusterApi.IssueApp)
	sub.GET("list/app", ClusterApi.AppList)
	sub.DELETE("app/:id", ClusterApi.DeleteApp)
	sub.GET("my/app", ClusterApi.AppList)
	sub.GET("app/:id", ClusterApi.GetIssueAppInfo)

}

func shHostRouter(r *gin.RouterGroup) {
	sub := r.Group("shHost")
	sub.Use(middleware.GinAuthorizationMiddleAware())

	sub.POST("add", ShHostApi.Add)
	sub.DELETE("delete/:id", ShHostApi.Delete)
	sub.GET("page", ShHostApi.Page)
}

func sessionRouter(r *gin.RouterGroup) {
	sub := r.Group("session")
	sub.Use(middleware.GinAuthorizationMiddleAware())

	sub.POST("gua/msg", SessionApi.SendInstruct)
	sub.POST("break/:id", SessionApi.Break)
	sub.POST("logoff/:id", SessionApi.Logoff)
	sub.GET("page", SessionApi.GetSessionPageForAdmin)
	sub.POST("app/log", SessionApi.InsertAppOpenLog)
	sub.POST("bind/winId", SessionApi.BindWinSessionId)
	sub.POST("create/:appId", SessionApi.CreateSession)
	sub.POST("check/:appId", SessionApi.CheckSessionReuse)
	sub.POST("resize", SessionApi.Resize)
}

func wsRouter(r *gin.RouterGroup) {
	sub := r.Group("session")
	sub.GET("gua/tunnel", GuaApi.Conn)
	sub.GET("gua/monitor", GuaApi.Monitor)
	sub.GET("gua/sh", GuaApi.SH)

	sub.GET("vnc", GuaApi.VNC)
}

func settingsRouter(r *gin.RouterGroup) {
	sub := r.Group("settings")
	sub.Use(middleware.GinAuthorizationMiddleAware())

	sub.GET("findGuaProperties", SettingsApi.FindGuaProperties)
	sub.POST("updateGuaProperty", SettingsApi.UpdateGuaProperty)

	sub.GET("findWatermark", SettingsApi.FindWatermark)
	sub.POST("saveWatermark", SettingsApi.SaveWatermark)
	sub.GET("getWatermarkContext", SettingsApi.GetWatermarkContext)

}

func remoteApi(r *gin.RouterGroup) {
	sub := r.Group("remote")

	sub.POST("createWinRdpAccount", SettingsApi.CreateWinRdpAccount)

}
